#include "CP_MainWindow.h"
#include <QFileDialog>
#include "CE.h"

CP_MainWindow::CP_MainWindow(QWidget *parent)
	: QMainWindow(parent)
{
	ui.setupUi(this);

	QPixmap playIcon(tr(":/Icon/Play"));
	QPixmap pauseIcon(tr(":/Icon/Pause"));
	QPixmap stopIcon(tr(":/Icon/Stop"));
	ui.mainToolBar->setIconSize(playIcon.size());

	QAction* playAction = ui.mainToolBar->addAction(QIcon(playIcon), tr("Play"));
	QAction* pauseAction = ui.mainToolBar->addAction(QIcon(pauseIcon), tr("Pause"));
	QAction* stopAction = ui.mainToolBar->addAction(QIcon(stopIcon), tr("Stop"));

	QObject::connect(playAction, SIGNAL(triggered()), this, SLOT(play()));
}

CP_MainWindow::~CP_MainWindow()
{

}

void CP_MainWindow::addCocosWidget(QWidget* pWidget)
{
    ui.cocosFrame->addWidget(pWidget, 0, 0, 1, 1);
}

void CP_MainWindow::open()
{
	QFileDialog dlg(this);
	dlg.setFileMode(QFileDialog::ExistingFile);
	int ret = dlg.exec();
	if(ret==0)
		return;
	QStringList files = dlg.selectedFiles();
	cocosFactoryEngineApp->load(files[0].toStdString().c_str());
}

void CP_MainWindow::play()
{
	cocosFactoryEngineApp->play();
}
